package com.company.beauty.common;


import cn.hutool.extra.spring.SpringUtil;
import com.company.beauty.common.config.*;
import com.company.beauty.common.constants.BeanConditionalConstants;
import com.company.beauty.common.handler.GlobalExceptionHandler;
import com.company.beauty.common.handler.HttpMessageResultHandler;
import com.company.beauty.common.handler.LogHandler;
import com.company.beauty.common.handler.ZkPlatformIdHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * <p>common auto configuration</p >
 *
 * @author youyoukele
 * @version 1.0
 * @date 2022/9/18
 */
@Slf4j
@Configuration(proxyBeanMethods = false)
@Import({
        SpringUtil.class,
        CacheConfiguration.class,
        StopWatchConfiguration.class,
        LarkNotificationConfiguration.class,
        JacksonBeanConfiguration.class,
        AsyncConfiguration.class,
        RestTemplateConfiguration.class,
        ValidatorConfiguration.class,
        RetryRequestConfiguration.class
})
@AutoConfigureAfter({
        JacksonBeanConfiguration.class,
        AsyncConfiguration.class,
        RestTemplateConfiguration.class
})
public class CommonAutoConfiguration {

    @Bean
    public LogHandler logHandler() {
        log.info("common log handler ==========>");
        return new LogHandler();
    }

    @Bean
    @ConditionalOnProperty(prefix = BeanConditionalConstants.Prefix.COMMON_PLATFORM, name = BeanConditionalConstants.FieldName.ENABLED, havingValue = "true", matchIfMissing = true)
    public ZkPlatformIdHandler ZkPlatformIdHandler() {
        log.info("common Zk-Platform-Id handler ==========>");
        return new ZkPlatformIdHandler();
    }

    @Bean
    public GlobalExceptionHandler globalExceptionHandler() {
        log.info("common global exception handler ==========>");
        return new GlobalExceptionHandler();
    }

    @Bean
    public HttpMessageResultHandler httpMessageResultHandler() {
        log.info("common httpMessageResultHandler ==========>");
        return new HttpMessageResultHandler();
    }

}
